<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_parametre=new parametre();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["code_param"])){$_parametre->set_code_param($_POST["code_param"]);}
		if(isset($_POST["nom_param"])){$_parametre->set_nom_param($_POST["nom_param"]);}
		if(isset($_POST["type_param"])){$_parametre->set_type_param($_POST["type_param"]);}
		if(isset($_POST["contraint_param"])){$_parametre->set_contraint_param($_POST["contraint_param"]);}
		if(isset($_POST["labell"])){$_parametre->set_labell($_POST["labell"]);}
		if(isset($_POST["valeur_param"])){$_parametre->set_valeur_param($_POST["valeur_param"]);}
		if(isset($_POST["valeur_extension"])){$_parametre->set_valeur_extension($_POST["valeur_extension"]);}
		$res=$_parametre->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["code_param"])){
		$_parametre->set_code_param($_POST["code_param"]);
		$res=$_parametre->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["code_param"])){$_parametre->set_code_param($_POST["code_param"]);}
		if(isset($_POST["nom_param"])){$_parametre->set_nom_param($_POST["nom_param"]);}
		if(isset($_POST["type_param"])){$_parametre->set_type_param($_POST["type_param"]);}
		if(isset($_POST["contraint_param"])){$_parametre->set_contraint_param($_POST["contraint_param"]);}
		if(isset($_POST["labell"])){$_parametre->set_labell($_POST["labell"]);}
		if(isset($_POST["valeur_param"])){$_parametre->set_valeur_param($_POST["valeur_param"]);}
		if(isset($_POST["valeur_extension"])){$_parametre->set_valeur_extension($_POST["valeur_extension"]);}
		$res=$_parametre->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["code_param"]) && !empty($_POST["code_param"])){
		$constraint.=" AND code_param='".$_POST["code_param"]."'";
	}

	if(isset($_POST["nom_param"]) && !empty($_POST["nom_param"])){
		$constraint.=" AND nom_param='".$_POST["nom_param"]."'";
	}

	if(isset($_POST["type_param"]) && !empty($_POST["type_param"])){
		$constraint.=" AND type_param='".$_POST["type_param"]."'";
	}

	if(isset($_POST["contraint_param"]) && !empty($_POST["contraint_param"])){
		$constraint.=" AND contraint_param='".$_POST["contraint_param"]."'";
	}

	if(isset($_POST["labell"]) && !empty($_POST["labell"])){
		$constraint.=" AND labell='".$_POST["labell"]."'";
	}

	if(isset($_POST["valeur_param"]) && !empty($_POST["valeur_param"])){
		$constraint.=" AND valeur_param='".$_POST["valeur_param"]."'";
	}

	if(isset($_POST["valeur_extension"]) && !empty($_POST["valeur_extension"])){
		$constraint.=" AND valeur_extension='".$_POST["valeur_extension"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_parametre->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_parametre->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>